//  this library.
import 'package:flutter/material.dart';
import 'package:hktk_app/util/font_util.dart';
import 'package:hktk_app/util/view_util.dart';
import 'package:hktk_app/widget/question/stem_rich_text_widget.dart';

/// 内容显示组件
class NoteItemWidget extends StatelessWidget {
  /// 发布者名
  final String? createName;

  /// 发布者头像
  final String? createHeader;

  /// 笔记内容
  final String? content;

  /// 内容字符大小控制
  final TextStyle contentStyle;

  const NoteItemWidget({
    super.key,
    required this.createName,
    required this.createHeader,
    required this.content,
    required this.contentStyle,
  });

  @override
  Widget build(BuildContext context) {
    debugPrint("nodeItemWidget 组件 -> build 方法执行 ===> ");
    debugPrint("");
    return Column(
      mainAxisSize: MainAxisSize.min,
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        _headItem(),
        hiSpace(height: 10),
        _nodeConItem(),
      ],
    );
  }

  /// 头部组件显示
  _headItem() {
    return Row(
      children: [
        _headLeftItem(),
        hiSpace(width: 30),
        Text(
          createName ?? "",
          style: FontUtil.fontGrey2(22),
        ),
      ],
    );
  }

  /// 头像显示
  _headLeftItem() {
    return Container(
      width: 64,
      height: 64,
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(32),
        border: Border.all(color: colorGrey19, width: 1),
      ),
      child: ClipOval(
        child: _clipItem(),
      ),
    );
  }

  /// 裁剪
  _clipItem() {
    if (createHeader == null || createHeader == "") {
      return Image.asset(
        "images/my/head.png",
        width: 64,
        height: 64,
        fit: BoxFit.cover,
      );
    } else {
      return Image.network(
        createHeader!,
        width: 64,
        height: 64,
        fit: BoxFit.cover,
      );
    }
  }

  /// 内容显示
  _nodeConItem() {
    return Container(
      padding: EdgeInsets.only(left: 90),
      child: StemRichTextWidget(
        text: content ?? "",
        textStyle: contentStyle,
      ),
    );
  }
}
